import { defineStore } from 'pinia'
import { ADMIN_LEVEL } from '@/enums/index.js'
// import { extractTree } from '@/utils'

export const GlobalStore = defineStore({
	id: 'global',
	state: () => ({
		token: '',
		socialId: '',
		openId: '',
		sessionId: '',
		sessionKey: '',
		nickName: '',
		companyId: '',
		times: ''
	}),
	actions: {
		setData(payload) {
			if (!payload) return
			const { openid, sessionId, session_key, nickName, times } = payload
			// console.log('setData', payload);
			this.openId = openid ?? ''
			this.sessionId = sessionId ?? ''
			this.sessionKey = session_key ?? ''
			this.nickName = nickName ?? ''
			this.times = times ?? ''
		},
		setSocialId(payload) {
			if (payload !== null) this.socialId = payload
		},
		setToken(payload) {
			if (payload !== null) this.token = payload
		},
		setCompanyId(payload) {
			if (payload !== null) this.companyId = payload
		},
		setNickName(payload) {
			if (payload !== null) this.nickName = payload
		},
	},
	// unistorage: true, // 开启后对 state 的数据读写都将持久化
})